package com.sk.cardeal.act.home.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.dyhdyh.widget.loading.dialog.LoadingDialog;
import com.sk.cardeal.R;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.callback.HandleDataCallBack;
import com.sk.cardeal.dialog.CountDialogFragment;
import com.sk.cardeal.entity.BussinessStatementBean;
import com.sk.cardeal.utils.AppApi;
import com.sk.cardeal.utils.DateUtils;
import com.sk.cardeal.utils.MyUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by sk on 2017/12/19.
 */

public class BusinessActivity extends BaseActivity implements HandleDataCallBack {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_day)
    TextView tvDay;
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.profit_tip)
    TextView profitTip;
    @BindView(R.id.tv_profit)
    TextView tvProfit;
    @BindView(R.id.tv_contrast)
    TextView tvContrast;
    @BindView(R.id.tv_total)
    TextView tvTotal;
    @BindView(R.id.tv_vip)
    TextView tvVip;
    @BindView(R.id.tv_custom)
    TextView tvCustom;

    @BindView(R.id.renew_money)
    TextView renewMoney;
    @BindView(R.id.renew_proportion)
    TextView renewProportion;
    @BindView(R.id.repayment_money)
    TextView repaymentMoney;
    @BindView(R.id.repayment_proportion)
    TextView repaymentProportion;
    @BindView(R.id.hour_parts_money)
    TextView hourPartsMoney;
    @BindView(R.id.hour_parts_proportion)
    TextView hourPartsProportion;
    @BindView(R.id.sale_moeny)
    TextView saleMoeny;
    @BindView(R.id.sale_proportion)
    TextView saleProportion;
    private LoadingDialog loadingDialog;

    @Override
    protected int getContentView() {
        return R.layout.activity_bussiness;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        loadingDialog = MyUtils.getLoadingDialog(mContext, false);
        AppApi.bussinessStatement(DateUtils.getTodayDate(), this, 0, this);
    }

    @Override
    public void handlerSuccessData(String result, int tag) {
        loadingDialog.cancelDialog();
        BussinessStatementBean bean = JSON.parseObject(result, BussinessStatementBean.class);
        tvProfit.setText(String.valueOf(bean.getReturnObject().getTurnover()));
        tvTotal.setText(String.valueOf(bean.getReturnObject().getCustomTotal()));
        tvVip.setText(String.valueOf(bean.getReturnObject().getVipTotal()));
        tvCustom.setText(String.valueOf(bean.getReturnObject().getCommonTotal()));
        tvContrast.setText(String.valueOf(bean.getReturnObject().getComWithYesTurnoverRate() + "%"));
        saleMoeny.setText(String.valueOf(bean.getReturnObject().getVipSaleCard()));
        saleProportion.setText(String.valueOf(bean.getReturnObject().getVipSaleCardRate() + "%"));
        renewMoney.setText(String.valueOf(bean.getReturnObject().getVipRenew()));
        renewProportion.setText(String.valueOf(bean.getReturnObject().getVipRenewRate() + "%"));
        repaymentMoney.setText(String.valueOf(bean.getReturnObject().getCustomRepay()));
        repaymentProportion.setText(String.valueOf(bean.getReturnObject().getCustomRepayRate() + "%"));
        hourPartsMoney.setText(String.valueOf(bean.getReturnObject().getPartsTotal()));
        hourPartsProportion.setText(String.valueOf(bean.getReturnObject().getPartsTotalRate() + "%"));
    }

    @Override
    public void handlerFailData(String failString, int tag) {
        loadingDialog.cancelDialog();
    }

    @Override
    public void handleErrorData(String error, int tag) {
        loadingDialog.cancelDialog();
    }

    @OnClick(R.id.tv_day)
    public void onViewClicked() {

        CountDialogFragment countDialogFragment = new CountDialogFragment();
        countDialogFragment.setMyCallBack(BusinessActivity.this);
        countDialogFragment.show(getSupportFragmentManager(),"tip");

    }

    @Override
    public void clickView(int id) {
        super.clickView(id);
        switch (id){
            case R.id.today:
                tvDay.setText("今日");
                break;
            case R.id.t_week:
                tvDay.setText("本周");
                break;
            case R.id.t_month:
                tvDay.setText("本月");
                break;
        }
    }
}
